package leetcode.string;

/**
 * @author : zx
 * @version V1.0
 */
public class Palindrome {
    public static boolean isPalindrome(String s) {
        char[] c = s.toCharArray();
        int n = c.length;
        int j = n-1;
        int i = 0;
        if(n==0 || n==1){
            return true;
        }
        while (i < n && j >= 0){
            while (!((c[j]<='Z'&& c[j]>='A') || (c[j]<='9' && c[j]>='0' || (c[j]<='z'&& c[j]>='a')))){
                j--;
                if (j<0){
                    return true;
                }
            }
            while (!((c[i]<='Z'&& c[i]>='A') || (c[i]<='9' && c[i]>='0') || (c[i]<='z'&& c[i]>='a'))){
                i++;
                if (i>=n){
                    return true;
                }
            }
            if (Character.toLowerCase(c[i]) != Character.toLowerCase(c[j])){
                return false;
            }else {
                i++;
                j--;
            }
            if (j<=i){
                return true;
            }
        }
        return true;
    }

    public static String generateTheString(int n) {
        if (n==0) return "";
        char a = 'a';
        char b = 'b';
        char[] r = new char[n];
        for (int i = 0; i < n; i++){
            r[i] = a;
        }
        if (n%2 == 0) r[n-1] = b;
        return new String(r);
    }

    public static void main(String[] args){
        System.out.println(isPalindrome("./"));
        System.out.println(isPalindrome("11221211"));
        System.out.println(isPalindrome("A man, a plan, a canal: Panama"));

        System.out.println(generateTheString(0));
        System.out.println(generateTheString(6));

    }
}
